package cn.eonshine.cuba.inf.modular.biz.service.impl;

import java.util.Date;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.eonshine.cuba.inf.modular.biz.entity.TrainGps;
import cn.eonshine.cuba.inf.modular.biz.mapper.TrainGpsMapper;
import cn.eonshine.cuba.inf.modular.biz.service.ITrainGpsService;
import cn.eonshine.cuba.inf.modular.common.service.AbstractCommonService;

/**
 * <p>
 * Train GPS(火车GPS) 服务实现类
 * </p>
 *
 * @author Alan
 * @since 2018-07-28
 */
@Service
@Transactional
public class TrainGpsServiceImpl extends AbstractCommonService<TrainGpsMapper, TrainGps> implements ITrainGpsService {

	@Override
	public int transportDataHandle(TrainGps obj, int count) throws Exception {
		String trainId = obj.getTrainId();
		Date dataInputDatetime = obj.getDataInputDatetime();
		QueryWrapper<TrainGps> entity = new QueryWrapper<TrainGps>();
//		entity.where("TRAIN_ID={0} and data_input_datetime={1}", trainId, dataInputDatetime);
		entity.lambda().eq(TrainGps::getTrainId, trainId);
		entity.lambda().eq(TrainGps::getDataInputDatetime, dataInputDatetime);
		boolean success = false;
		if(this.isUpdate==0){
			success = remove(entity);
		}else {
			success = update( obj,entity);
		}
		if (success) {
			count++;
		}
		return count;
	}

	@Override
	public void mappingHandle(TrainGps obj) throws Exception {
		// mapping TABLE
//		Mapping map = new Mapping();
//		QueryWrapper<Mapping> entitys = new QueryWrapper<Mapping>();
//		map.setLsmsId(obj.getId());
//		map.setDmz1(obj.getTrainId());
//		map.setDataType(InfStatus.DMZ_MAPPING_TRAIN_GPS);
//		entitys.eq("lsms_id", obj.getId());
//		Mapping maps = mappingService.selectOne(entitys);
//		if (maps == null) {
//			mappingService.insert(map);
//		}else {
//			mappingService.update(map, entitys);
//		}
	}

	@Override
	public boolean isUseCutomerSelectSQL() {
		return false;
	}

}
